<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>计算数组的交集</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-intersect-ukey.html">array_intersect_ukey</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-key-exists.html">array_key_exists</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-intersect" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_intersect</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">array_intersect</span> &mdash; <span class="dc-title">计算数组的交集</span></p>

   </div>
   
 <div class="refsect1 description" id="refsect1-function.array-intersect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_intersect</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$array2</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ ...</code></span>
  ] )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_intersect()</strong></span> 返回一个数组，该数组包含了所有在
     <em><code class="parameter">array1</code></em> 中也同时出现在所有其它参数数组中的值。注意键名保留不变。
    </p>
  </div>

   
    <div class="refsect1 parameters" id="refsect1-function.array-intersect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">array1</code></em></dt>

     <dd>

      <p class="para">
       The array with master values to check.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">array2</code></em></dt>

     <dd>

      <p class="para">
       An array to compare values against.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">array</code></em></dt>

     <dd>

      <p class="para">
       A variable list of arrays to compare.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
    <div class="refsect1 returnvalues" id="refsect1-function.array-intersect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    返回一个数组，该数组包含了所有在
     <em><code class="parameter">array1</code></em> 中也同时出现在所有其它参数数组中的值。
  </p>
 </div>
 
   
    <div class="refsect1 examples" id="refsect1-function.array-intersect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4854">
    <p><strong>Example #1 <span class="function"><strong>array_intersect()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"blue"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$array2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"yellow"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_intersect</span><span style="color: #007700">(</span><span style="color: #0000BB">$array1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [a] =&gt; green
    [0] =&gt; red
)
</pre></div>
    </div>
   </div>
  </p>
 </div>

  
 <div class="refsect1 notes" id="refsect1-function.array-intersect-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
     两个单元仅在 <em>(string) $elem1 === (string) $elem2</em>
      时被认为是相同的。也就是说，当字符串的表达是一样的时候。
      
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-intersect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-intersect-assoc.html" class="function" rel="rdfs-seeAlso">array_intersect_assoc()</a> - 带索引检查计算数组的交集</span></li>
    <li class="member"><span class="function"><a href="function.array-diff.html" class="function" rel="rdfs-seeAlso">array_diff()</a> - 计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-diff-assoc.html" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - 带索引检查计算数组的差集</span></li>
   </ul>
  </p>
 </div>


  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-intersect-ukey.html">array_intersect_ukey</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-key-exists.html">array_key_exists</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
